package com.jz.cost.mapper;

import com.jz.cost.model.*;
import com.jz.legalpersonclass.model.LegalPersonVo;
import com.jz.planclass.model.PlanClassVo;
import com.jz.subclass.model.SubClassVo;
import com.jz.util.PageVo;
import org.apache.ibatis.annotations.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Date;
import java.util.List;

/**
 * Created by WISE on 2021/12/26.
 */
@Mapper
public interface CostMapper {


    List<CostVo> queryData(CostSelectVo costSelectVo);

    int queryCount(CostSelectVo costSelectVo);

    @Select("select * from partclass where code = #{code}")
    CostVo queryByCode(String code);

    @Select("select * from partclass where name = #{name}")
    CostVo queryByName(String name);

    @Insert("insert into cost(priceType,legalPersonCode,partCode,currencyCode,price,taxType,startTime,endTime,remark,createTime,createName,status)" +
            "values(#{priceType},#{legalPersonCode},#{materialCode},#{currencyCode},#{price},#{taxType},#{startTime},#{endTime},#{remark},#{createTime},#{createName},0)")
    void add(CostVo costVo1);

    @Insert("insert into cost(priceType,legalPersonCode,partCode,currencyCode,price,taxType,startTime,endTime,remark,createTime,createName,status)" +
            "values(#{priceType},#{legalPersonCode},#{partCode},#{currencyCode},#{price},#{taxType},#{startTime},#{endTime},#{remark},#{createTime},#{createName},0)")
    void addP(CostVo costVo1);

    @Select("select * from partclass where id = #{id}")
    List<CostVo> queryById(Integer id);

    @Select("select code subCode from subclass where subName = #{subName}")
    CostVo queryBySubName(@NotBlank(message = "备件小类名称不能为空") String subName);

    @Select("select code planCode from planclass where planName = #{planName}")
    CostVo queryByPlanName(@NotBlank(message = "备件小类名称不能为空") String planName);

    @Select("select *  from legalpersonclass where legalPersonCode = #{legalPersonCode}")
    CostVo queryLegalPerson(@NotBlank(message = "法人名称不能为空") String legalPersonName);

    @Select("select *  from partclass where partCode = #{partCode}")
    CostVo queryPart(@NotBlank(message = "法人名称不能为空") String legalPersonName);

    @Select("select legalPersonCode ,legalPersonName  from legalpersonclass where userId = #{userId}")
    List<CostVo> queryByUserId(Integer userId);

    @Select("select * from cost ")
    List<CostVo> queryStartTime();

    @Insert("insert into partlegal(partCode,legalCode) values (#{code},#{legalCode})")
    void add1(CostVo classVo);

    @Update("update cost set priceId = #{priceId},status = #{status},updateTime = #{updateTime},updateName = #{updateName},partCode = #{partCode},currencyId = #{currencyId},taxId = #{taxId},price = #{price},remark = #{remark},legalPersonCode = #{legalPersonCode} where id = #{id}")
    int update(CostVo classVo);

    @Update("update cost set status = #{status},updateTime = #{updateTime},updateName = #{updateName} where id = #{id}")
    void updateStatus(CostVo costVo);

    @Select("select * from price ")
    List<PriceVo> queryPrice();

    @Update("update cost set endTime = #{endTime},updateTime = #{updateTime},updateName = #{updateName} where id = #{id}")
    void updateEndTime(CostVo costVo);

    @Select("select * from tax ")
    List<TaxVo> queryTax();

    @Delete("delete from cost where partCode = #{partCode}")
    void deletePartCode(@NotBlank(message = "备件编码不能为空") String partCode);

    @Select("select * from tax")
    List<TaxVo> queryAllTaxType();

    @Select("select * from cost where legalPersonCode = #{legalPersonCode} and partCode = #{materialCode}")
    List<CostVo> queryByPartAndLegal(CostAddVo costAddVo);

    @Select("select * from cost where legalPersonCode = #{legalPersonCode} and partCode = #{materialCode}")
    List<CostVo> queryByPartAndLegal2(CostUpdateVo costUpdateVo);

    @Delete("delete from cost where id = #{id}")
    void deleteByCostId(Integer id);

    @Select("select id from cost where startTime = #{date}and status =0")
    List<Integer> selectStartTime(Date date);

    @Select("select id from cost where endTime <= #{date}and status =1")
    List<Integer> selectEndTime(Date date);

    @Update("update cost set startTime = #{startTime},endTime = #{endTime},remark = #{remark},price = #{price} where id = #{id}")
    void updateCost(CostVo costVo);
}
